

$(document).ready(function(){
	    //banner图图片地址
    initFileInput("fileupload", urlcore + "/api/attachment/upload", "#picturesUrl");

    if(location.href.indexOf("?type")>-1){
        var type = location.href.split("?type=")[1];
        $("#eachType").find("option").eq(type-1).prop("selected",true);
    }


});


function onSave(){
	var eachType=$("#eachType").val();
    //活动图片地址
    var picUrl = "";

    var flag = true;

    $("#picturesUrl img").each(function(index,item){
        if(index == 0){
            picUrl += $(this).attr("src")+"***";
            flag =true;
        }else{
            flag = false;
            return;
        }

    });
	if(picUrl!=""){
		  picUrl = picUrl.substring(0, picUrl.length-3);
	}
	var goodsId=$("#goodsId").val();
    console.log(picUrl);
	if(flag){
        $.ajax({
            type: "POST",
            url: urlcore + "/api/eachPicture/add",
            dataType: "json",
            contentType: "application/json;charset=UTF-8",
            data:JSON.stringify({
                eachType:eachType,
                pictureUrl:picUrl,
                intentUrl:$("#intentUrl").val(),
                goodsId:goodsId
            }),
            success: function (data) {
                console.log(data)
               if(data.success){
                   alert("添加成功");
                   window.location.href="eachPic_list.html";
               }else{
                    alert(data.msg);
               }
            },
            error: function () {
                alert("失败");
            }
        });
    }else{
        alert("一次只能上传一张图片！");
    }



	
	
	
}


